package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: fqy
 * Date: 2021/10/15
 * Time: 16:12
 * Describe:
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Map<String, Object> getSupplierPage(Integer page, Integer rows, String supplierName) {
        HashMap<String, Object> map = new HashMap<>();
        PageHelper.startPage(page, rows);
        List<Supplier> supplierList = supplierDao.selectSupplierPage(page,rows,supplierName);
        PageInfo<Supplier> supplierListPageInfo = new PageInfo<Supplier>(supplierList);
        // total 总记录数 rows 记录
        map.put("total", supplierListPageInfo.getTotal());
        map.put("rows", supplierListPageInfo.getList());
        return map;
    }
    //  添加供应商
    @Override
    public void insertSupplier(Supplier supplier) {
        String supplierName = supplier.getSupplierName();
        String address = supplier.getAddress();
        String contacts = supplier.getContacts();
        String remarks = supplier.getRemarks();
        String phoneNumber = supplier.getPhoneNumber();
        supplierDao.insertSupplier(supplier);
    }
    //  修改供应商
    @Override
    public void updateSupplier(Supplier supplier, Integer supplierId) {
        supplierDao.updateSupplier(supplier,supplierId);
    }
    // 根据ids批量删除供应商
    @Override
    public int deleteSupplierBachByIds(String[] arr) {
        int i = supplierDao.deleteSupplierBachByIds(arr);
        return i;
    }
}
